package com.example.mobile2121606109ycg0514homework1;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

public class CarPartsActivity2 extends AppCompatActivity {

    private CheckBox chbCarPart1;
    private CheckBox chbCarPart2;
    private CheckBox chbCarPart3;
    private CheckBox chbCarPart4;
    private CheckBox chbCarPart5;
    private CheckBox chbCarPart6;
    private CheckBox chbCarPart7;
    private CheckBox chbCarPart8;
    private CheckBox chbCarPart9;
    private CheckBox chbCarPart10;
    private CheckBox chbCarPart11;
    private Button btnCarPartShoppingCart;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_car_parts2);
        initView();

        btnCarPartShoppingCart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String carParts = "";
                if (chbCarPart1.isChecked()==true){
                    carParts+=chbCarPart1.getText().toString()+"\n";
                }if (chbCarPart2.isChecked()==true){
                    carParts+=chbCarPart2.getText().toString()+"\n";
                }if (chbCarPart3.isChecked()==true){
                    carParts+=chbCarPart3.getText().toString()+"\n";
                }if (chbCarPart4.isChecked()==true){
                    carParts+=chbCarPart4.getText().toString()+"\n";
                }if (chbCarPart5.isChecked()==true){
                    carParts+=chbCarPart5.getText().toString()+"\n";
                }if (chbCarPart6.isChecked()==true){
                    carParts+=chbCarPart6.getText().toString()+"\n";
                }if (chbCarPart7.isChecked()==true){
                    carParts+=chbCarPart7.getText().toString()+"\n";
                }if (chbCarPart8.isChecked()==true){
                    carParts+=chbCarPart8.getText().toString()+"\n";
                }if (chbCarPart9.isChecked()==true){
                    carParts+=chbCarPart9.getText().toString()+"\n";
                }if (chbCarPart10.isChecked()==true){
                    carParts+=chbCarPart10.getText().toString()+"\n";
                }if (chbCarPart11.isChecked()==true){
                    carParts+=chbCarPart11.getText().toString()+"\n";
                }
                if (carParts == ""){
                    new AlertDialog.Builder(CarPartsActivity2.this)
                            .setMessage("请选择原材料")
                            .setPositiveButton("确定",null)
                            .create()
                            .show();
                }else {
                    Intent intent = new Intent();
                    intent.putExtra("carParts",carParts);
                    setResult(RESULT_OK,intent);
                    finish();
                }
            }
        });
    }

    private void initView() {
        chbCarPart1 = (CheckBox) findViewById(R.id.chbCarPart1);
        chbCarPart2 = (CheckBox) findViewById(R.id.chbCarPart2);
        chbCarPart3 = (CheckBox) findViewById(R.id.chbCarPart3);
        chbCarPart4 = (CheckBox) findViewById(R.id.chbCarPart4);
        chbCarPart5 = (CheckBox) findViewById(R.id.chbCarPart5);
        chbCarPart6 = (CheckBox) findViewById(R.id.chbCarPart6);
        chbCarPart7 = (CheckBox) findViewById(R.id.chbCarPart7);
        chbCarPart8 = (CheckBox) findViewById(R.id.chbCarPart8);
        chbCarPart9 = (CheckBox) findViewById(R.id.chbCarPart9);
        chbCarPart10 = (CheckBox) findViewById(R.id.chbCarPart10);
        chbCarPart11 = (CheckBox) findViewById(R.id.chbCarPart11);
        btnCarPartShoppingCart = (Button) findViewById(R.id.btnCarPartShoppingCart);
    }
}